# 数组的排序
import numpy as np

n = np.array([[4, 7, 3], [2, 8, 5], [9, 1, 6]])
print(n)

print('数组排序', np.sort(n))  # 排序默认升序，按列排序

# 按行排序
print(np.sort(n, axis=0))

# 按列排序
print(np.sort(n, axis=1))

# argsort() 排序
x = np.array([9, 4, 7, 2, 4, 8, 3])
y = np.argsort(x)
print(y)  # 得到升序排序后的索引值
# 排序后重构数组
print(x[y])

# lexsort() 排序
math = np.array([101, 109, 115, 108, 118, 112, 118])
english = np.array([117, 105, 118, 98, 109, 98, 120])
total = np.array([621, 623, 620, 620, 615, 615, 450])

sort_total = np.lexsort((english, math, total))  # 先按总分，再比数学，最后比英语
print(sort_total)  # 排序后的索引值
lst = [[total[i], math[i], english[i]] for i in sort_total]
n = np.array(lst)
print(n)
